#include "common.h"

string convert(string s, int numRows)
{
	if (numRows == 1) return s;
	string ans;
	vector<vector<char>> record(numRows, vector<char>(s.size(), ' '));
	int i = 0;
	int col = 0;
	int row = 0;
	while (i < s.size())
	{
		if (col % (numRows - 1) == 0)
		{
			record[row][col] = s[i];
			i++;
			row++;
			if (row == numRows)
			{
				col++;
				row = 0;
			}
		}
		else
		{
			record[numRows - 1 - (col % (numRows - 1))][col] = s[i];
			i++;
			col++;
		}
	}
	for (int i = 0; i < numRows; i++)
	{
		for (int j = 0; j <= col; j++)
		{
			if (record[i][j] != ' ') ans.push_back(record[i][j]);
		}
	}
	return ans;
}